<?php
namespace app\controller;

use app\BaseController;
use think\facade\Db;

class User extends BaseController
{
    public function add()
    {
		//1 获取前端的数据
		$inputData = json_decode(file_get_contents("php://input"),true);
		//dump($userData);
		$userInsertData = [
			"username"=>$inputData["username1"],
			"password"=>$inputData["password1"],
			"gender"=>$inputData["gender"]
		];
		//2 写入数据库
		$id= Db::name('user')->insertGetId($userInsertData);
		$userInsertData["id"] = $id;
		if($id){
			$msg = [
				"isOk"=>true,
				"message"=>"新添成功",
				"data"=> $userInsertData
			];
			return json($msg);
		}else{
			$msg = [
				"isOk"=>false,
				"message"=>"插入数据库失败",
				"data"=> $userInsertData
			];
			return json($msg);
		}
    }

    
}
